/**
 * @Author：ming
 * @Date：2023/10/29 10:18 PM
 * @Filename：Hot121
 */

/**
 * @author ming
 */
public class Hot121 {
    public int maxProfit(int[] prices) {
        int profit =0;
        int max =0;
        int buy = prices[0];
        for (int i = 0; i < prices.length; i++) {

            if(prices[i]>buy){
                profit = prices[i]-buy;
                if(profit>max){
                    max = profit;
                }
            }
            if(prices[i]<buy){
                buy = prices[i];
            }
        }
        return max;
    }
}
